package com.koicarp.university.graduate.web.controller;

import com.github.jsonldjava.utils.Obj;
import com.koicarp.university.graduate.auth.annotation.OperLog;
import com.koicarp.university.graduate.auth.constant.ModuleNameEnum;
import com.koicarp.university.graduate.auth.constant.OperateLogTypeEnum;
import com.koicarp.university.graduate.service.entity.graduateInfoManage.GraduateInfo;
import com.koicarp.university.graduate.service.service.graduateInfoManage.IGraduateInfoService;
import com.koicarp.university.graduate.service.vo.graduateInfoManage.DeleteMoreDto;
import com.koicarp.university.graduate.service.vo.graduateInfoManage.GraduateInfoVo;
import com.koicarp.university.graduate.service.vo.graduateInfoManage.InfoStatusVo;
import com.koicarp.university.graudate.common.constant.BaseConstant;
import com.koicarp.university.graudate.common.utils.UniversityResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * 【毕业生管理：毕业生信息表】(GraduateInfo)表控制层
 *
 * @author liutao
 * @since 2020-09-03 19:53:51
 */
@RestController
@RequestMapping("graduateInfo")
@Slf4j
@RequiredArgsConstructor
@Api(tags = "(毕业生信息表)控制层")
public class GraduateInfoController {
    /**
     * 服务对象
     */

    private final IGraduateInfoService graduateInfoService;


    @PostMapping("getGraduateInfoWithPage")
    @ApiOperation(value = "查询毕业生信息，分页",notes = "附带条件和模糊查询")
    public UniversityResponse getGraduateInfoWithPage(@RequestBody GraduateInfoVo vo){
        UniversityResponse response=null;
        try{
            if (vo.getSort().equals("+id")){
                vo.setSort("asc");
            }else{
                vo.setSort("desc");
            }
            response = graduateInfoService.getGraduateInfoWithPage(vo);
        }catch (Exception e){
            log.error("查询失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }
    @PostMapping("saveGraduateInfo")
    @ApiOperation(value = "添加毕业生信息",notes = "单个信息添加")
    @OperLog(moduleName = ModuleNameEnum.GraManage,type = OperateLogTypeEnum.CREATE,operDesc = "添加毕业生信息")
    public UniversityResponse saveGraduateInfo(@RequestBody InfoStatusVo infoStatusVo){
        UniversityResponse response=null;
        try{
            response = graduateInfoService.insert(infoStatusVo);
        }catch (Exception e){
            log.error("查询失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }
    @PostMapping("removeGraduateInfo")
    @ApiOperation(value = "根据学生学号删除毕业生信息",notes = "单个删除")
    @OperLog(moduleName = ModuleNameEnum.GraManage,type = OperateLogTypeEnum.DELETE,operDesc = "单个删除")
    public UniversityResponse removeGraduateInfo(@RequestBody InfoStatusVo infoStatusVo){
        UniversityResponse response=null;
        try{
            response = graduateInfoService.deleteByStudentId(infoStatusVo);
        }catch (Exception e){
            log.error("查询失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }
    @PostMapping("removeListInfo")
    @ApiOperation(value = "根据学生学号批量删除毕业生信息",notes = "批量删除")
    @OperLog(moduleName = ModuleNameEnum.GraManage,type = OperateLogTypeEnum.DELETE,operDesc = "批量删除")
    public UniversityResponse removeListInfo(@RequestBody List<DeleteMoreDto> list){
        UniversityResponse response=null;
        try{
            response = graduateInfoService.deleteListByStudentId(list);
        }catch (Exception e){
            log.error("查询失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }
    @PostMapping("modifyGraduateInfo")
    @ApiOperation(value = "修改毕业生信息",notes = "修改毕业生信息,毕业生状态")
    @OperLog(moduleName = ModuleNameEnum.GraManage,type = OperateLogTypeEnum.UPDATE,operDesc = "修改毕业生信息,毕业生状态")
    public UniversityResponse modifyGraduateInfo(@RequestBody InfoStatusVo infoStatusVo){
        UniversityResponse response=null;
        try{
            response = graduateInfoService.update(infoStatusVo);
        }catch (Exception e){
            log.error("修改失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @GetMapping("downloadTemplate")
    @ApiOperation(value = "毕业学生数据模板",notes = "下载")
    @OperLog(moduleName = ModuleNameEnum.GraManage,type = OperateLogTypeEnum.DOWNLOAD,operDesc = "毕业学生数据模板")
    public void downloadTemplate(HttpServletResponse http) throws Exception{
        try {
            //DownLoadUtil.downloadFile(parkInfoTemplate,response);
            graduateInfoService.downloadTemplate(http);
        } catch (Exception e){
            log.error("下载模板失败",e);
        }
    }

    @PostMapping("uploadGraduateInfo")
    @ApiOperation("上传excel格式增加毕业生数据")
    @OperLog(moduleName = ModuleNameEnum.GraManage,type = OperateLogTypeEnum.UPLOAD,operDesc = "上传excel格式增加毕业生数据")
    public UniversityResponse uploadGraduateInfo(@RequestBody List<InfoStatusVo> tmp ) {
        UniversityResponse response=null;
        try{
            response = graduateInfoService.uploadGraduateInfo(tmp);
        }catch (Exception e){
            log.error("修改失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public GraduateInfo selectOne(Integer id) {
        return this.graduateInfoService.queryById(id);
    }

}